﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Linq;
using suirui.ZhuMu.Model;

namespace suirui.ZhuMu.Common.Utils
{
    public static class RequestChecker
    {
        private static void SetErrorParam(APIResult result)
        {
            result.Code = (int)PublicErrorCode.ParamInvlid;
            result.Message = MessageCollection.ParamError;
        }

        #region 检查文件上传
        /// <summary>
        /// 上传文件的参数验证
        /// </summary>
        public static bool CheckFileUploadRequest(this APIResult result, IFormCollection request)
        {
            if (request == null || request.Files == null || request.Files.Count != 1)
            {
                SetErrorParam(result);
                return false;
            }
            return true;
        }

        /// <summary>
        /// 上传文件的参数验证
        /// </summary>
        public static bool CheckFileUploadRequest(this APIResult result, IFormFile request)
        {
            if (request == null)
            {
                SetErrorParam(result);
                return false;
            }
            return true;
        }
        #endregion
    }
}
